<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="com.qijia.travel.app.*"  %>
<%@ page import="com.qijia.travel.domain.*"  %>
<%@ page import="com.qijia.travel.common.*"  %>
<%
Guide guide = (Guide)session.getAttribute(Constants.USER_KEY);
if(guide.getGuideType()==null||guide.getGuideType()!=1)
out.println("<script>alert('你没有此权限，请联系管理员开通此权限!');window.close();window.parent.location.reload();</script>");

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String treamId = request.getParameter("treamId");
TreamManager treamManager = new TreamManager();
Tream tream = new Tream();

boolean modify = false;
if(treamId!=null)modify = true;
System.out.println(treamId);

if(modify){
try{
   int ID = Integer.parseInt(treamId);
   tream = treamManager.getTreamById(ID);
   if(tream==null){
      out.println("<script>alert('该团队不存在');window.close();window.parent.location.reload();</script>");
   }
 }catch(NumberFormatException e){
   out.println("<script>alert('该团队不存在');window.close();window.parent.location.reload();</script>");
 }catch(AppErrorException ex){
   out.println("<script>alert('获取数据失败!');window.close();window.parent.location.reload();</script>");
}
}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
body {
	margin:0;
	padding:10px 0;
	font-size:12px;
}
ul,li{
    list-style:none;
}
textarea{width:150px;font-size:12px;}
.ipt{width:150px;}
.ipt2{width:40px;}
.btn{border:#002d96 1px solid; padding:4px 4px 2px; font-size:12px; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#FFFFFF, EndColorStr=#9DBCEA); cursor:hand; color:black;}
#wrapper{
	width:460px;
	height:280px;
	margin:0 auto;
	overflow:hidden;
}
#content{
    float:left;
	width:460px;
	height:auto;
	padding:10px 0;
}
#content ul{
	float:left;
	width:100%;
	height:auto;
}
#content li{
	float:left;
	width:100%;
	height:auto;
	line-height:30px;
}
#content span{
    float:left;
	display:block;
	width:100px;
	text-align:right;
}
-->
</style>
</head>

<body>
<div id="wrapper">
    <form method="post" action="">
    <div id="content">
	    <ul>
		    <li><span>团队名称：</span><input type="text" name="tream.treamName" class="ipt" value="<%=tream.getTreamName()==null?"":tream.getTreamName()%>"/></li>
			<li><span>团队描述：</span>
			<textarea rows="5" cols="8" name="tream.treamDesc" id="treamDesc">
			<%=tream.getTreamDesc()==null?"":tream.getTreamDesc()%>
			</textarea>
			<% if(modify){%>
			<li style="padding:0 0 0 100px;"><input name="" type="button" class="btn" value="确定" onclick="updateTream()"/></li>
		    <%}else{%>
		    <li style="padding:0 0 0 100px;"><input name="" type="button" class="btn" value="确定" onclick="createTream()"/></li>
		    <%}%>
		</ul>
	</div>
	</form>
</div>
<script src="<%=basePath%>dwr/interface/treamManager.js"></script>
<script src="<%=basePath%>dwr/engine.js"></script>
<script src="<%=basePath%>js/jquery.js"></script>
<script>
<% if(modify){%>
 function updateTream(){
   var data=new Object;
   data['treamId']=<%=treamId%>;
   $("textarea[name^=tream]").each(function(e){
       this.name=this.name.substring(this.name.indexOf(".")+1);
       if($.trim(this.value)!="")
       data[this.name]=this.value;
   });
   $("input[name^=tream]").each(function(e){
       if(this.type=="radio" && !this.checked)return;
       this.name=this.name.substring(this.name.indexOf(".")+1);
       if($.trim(this.value)!="")
       data[this.name]=this.value;
   });
   treamManager.updateTream(data,function(e){
     alert("修改成功!");
     window.close();
     window.parent.location.reload();
   });
 }
<%}else{%>
 function createTream(){
   var data=new Object;
   $("input[name^=tream]").each(function(e){
       this.name=this.name.substring(this.name.indexOf(".")+1);
       if($.trim(this.value)!="")
       data[this.name]=this.value;
   });
   $("textarea[name^=tream]").each(function(e){
       this.name=this.name.substring(this.name.indexOf(".")+1);
       if($.trim(this.value)!="")
       data[this.name]=this.value;
   });
   treamManager.createTream(data,function(e){
     alert("添加成功!");
     window.close();
     window.parent.location.reload();
   });
 }
 <%}%>
</script>
</body>
</html>
